﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Web;
//using Cqrs.Infrastructure;
//using Harmonic.Commands;
//using Harmonic.Domain;
//using Harmonic.ReadModel;
//using Newtonsoft.Json;

//namespace Harmonic
//{
//    public static class ServiceLocator
//    {
//        public static CommandBus CommandBus = new CommandBus();
//        private static EventPublisher EventPublisher = new EventPublisher();
//        private static EventStore EventStore = new EventStore(GetConnectionString(), EventPublisher);
//        private static Repository<Domain.User> Repository = new Repository<Domain.User>(EventStore);
//        private static CommandHandlers CommandHandler = new CommandHandlers(Repository);
//        private static RegisterUserEventHandlers registerUserEventHandlers = new RegisterUserEventHandlers();

//        public static void Build()
//        {
//            CommandBus.RegisterHandler<RegisterNewUser>(CommandHandler.Submit);
//            EventPublisher.RegisterHandler<UserCreated>(registerUserEventHandlers.Handle);
//        }

//        public static void DispatchCommand(ICommand command)
//        {
//            CqrsHost.CqrsServiceClient client = new CqrsHost.CqrsServiceClient();
//            client.SubmitCommand(JsonConvert.SerializeObject(command), command.GetType().AssemblyQualifiedName);
//        }

//        private static string GetConnectionString()
//        {
//            System.Configuration.Configuration rootWebConfig =
//                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/");
//            System.Configuration.ConnectionStringSettings connString;
//            if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0)
//            {
//                connString =
//                    rootWebConfig.ConnectionStrings.ConnectionStrings["EventStore"];
//                if (connString != null)
//                    return connString.ConnectionString;
//                else
//                    throw new Exception("Connection String not found");
//            }
//            else
//                throw new Exception("Connection String not found");
//        }
//    }
//}